package cn.tedu.gateway.controller;

import cn.tedu.gateway.ip.RedisIpListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

@RestController
@RequestMapping("/ip")
public class IpLIstController {
    @Autowired
    RedisIpListService redisIpListService;

    @GetMapping("/blacklist")
    public Set<String> getBlackList() {
        return redisIpListService.getBlackList();
    }

    @GetMapping("/whitelist")
    public Set<String> getWhiteList() {
        return redisIpListService.getWhiteList();
    }

    @PostMapping("/blacklist/{ip}")
    public void addToBlackList(@PathVariable String ip) {
        redisIpListService.addToBlackList(ip);
    }

    @PostMapping("/whitelist/{ip}")
    public void addToWhiteList(@PathVariable String ip) {
        redisIpListService.addToWhiteList(ip);
    }

    @DeleteMapping("/blacklist/{ip}")
    public void removeFromBlackList(@PathVariable String ip) {
        redisIpListService.removeFromBlackList(ip);
    }

    @DeleteMapping("/whiteklist/{ip}")
    public void removeFromWhiteList(@PathVariable String ip) {
        redisIpListService.removeFromWhiteList(ip);
    }
}
